#include "stdafx.h"
#include "Player.h"
#include "../../../EdgeGraphics/Model.h"
#include "../../../EdgeContent\ContentManager.h"
#include "../../../EdgeControls\Input.h"
#include "../../../EdgeControls\Controls.h"
#include "..\..\..\EdgeMath\BoundingBox.h"
#include "..\..\..\EdgeAudio\AudioManager.h"
#include "../../../EdgeAudio/SoundEffect2D.h"
#include "../../../EdgeGraphics/Camera.h"
#include "../../../EdgeControls/Controls.h"
#include "../Human.h"

void player_onCollision(void**);

Player::Player(Human* human) : move_speed(100.f)
{
	human->AddRef();
	human->setAgent(this);
	this->human = human;
	// inilitize controls
	InitControls();

	stats.exposure = 100.f;
	stats.thurst = 100.f;
	stats.hunger = 100.f;
	stats.health = 0.f;
	stats.healthRegen = 1.f;
	stats.stamina = 0.f;
	stats.staminaRegen = 10.f;

	human->OnCollision.Subscribe(Functor<collision_event_handler>(&player_onCollision, 0));

	/***********************Temporary********************************/
	sound = ContentManager::GetInstance()->LoadSoundEffect2D("Content/Sounds/pruneJuice.wav");

	/****************************************************************/
}

/*virtual*/ Player::~Player(void)
{
	human->Release();
	delete sound;
}

/*virtual*/ ControlableGameObject* Player::getTarget(void) const /*override*/ { return human; }

/*virtual*/ void Player::Update(float dt) /*override*/
{
	AudioManager::GetInstance()->setWorldListenPosition(Camera::GetInstance()->getWorldPosition());

	if (human->getScale() > 1.f)
		human->setScale(human->getScale() - 0.01f);
	
	stats.hunger -= dt;
	stats.thurst -= dt;
	stats.exposure -= dt;

	if (stats.health < 100.f)
		stats.health += stats.healthRegen * dt;
	if (stats.stamina < 100.f)
		stats.stamina += stats.staminaRegen * dt;

	UpdateControls(dt);
	if (scale > 1.f)
		scale -= .1f;
	if (scale < 1.f)
		scale += .1f;
}

/*virtual*/ void Player::Draw(void) /*override*/
{
}

/*static*/ Player* Player::GetInstance(void)
{
	static Player* instance;
	if (!instance)
	{
		Human* human = new Human;
		instance = new Player(human);
		human->setAgent(instance);
		human->Release();
	}

	return instance;
}

void player_onCollision(void** params)
{

}